import {useRequest} from 'ahooks';
import React from 'react';
function getName(){
	return new Promise((resolve,reject)=>{
		setTimeout(()=>{
			resolve('ok');
			//reject('fail');
		},3000);
	});
}
function App() {
	//在组件初次加载的时候会调用getName方法
	//调用getName方法的时候，会先返回一个对象{data:null,error:null,loading:true}
	const {data,error,loading} = useRequest(getName);
	console.log(data,error,loading);
	if(loading){
		return <div>loading name....</div>
	}
	if(error){
		return <div>load name error</div>
	}
	return (
		<div>
			name:{data}
		</div>
	);
}

export default App;
